package com.gujiangbo.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/6/2 09:52
 * @Version: 1.0
 * @Description:
 */
public class FutureTaskTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

       FutureTask<String> future = new FutureTask<>(new MyThread());

        Thread thread = new Thread(future);
        thread.start();
        System.out.println(future.get());


    }

}

class MyThread implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println("coming .....");
        //暂停10秒钟线程
        try{
            TimeUnit.SECONDS.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}
        return "Hello Java!";
    }
}
